'use strict'

module.exports = app => {
	const { STRING, INTEGER, DATE, TEXT } = app.Sequelize

	const Article = app.model.define('article', {
		id: { type: INTEGER, primaryKey: true, autoIncrement: true },
		title: {
			type: STRING,
			field: '_title',
			comment: '文章标题',
		},
		content: {
			type: TEXT,
			field: '_content',
			comment: '文章内容',
		},
		cover: {
			type: STRING,
			field: '_cover',
			comment: '文章配图',
		},
		authorId: {
			type: INTEGER,
			comment: '作者ID',
		},
		tagId: {
			type: INTEGER,
			comment: '分类ID',
		},
		status: {
			type: INTEGER,
			field: '_status',
			comment: '状态 0未审核 1审核中 2审核通过 3审核拒绝',
		},
		showHome: {
			type: INTEGER,
			comment: '首页展示  1展示 0不展示',
		},
		createdAt: DATE,
		updatedAt: DATE,
	})
	Article.associate = function () {
		app.model.Article.belongsTo(app.model.User, {
			foreignKey: 'authorId',
			targetKey: 'id',
		})
		app.model.Article.belongsTo(app.model.Tag, {
			foreignKey: 'tagId',
			targetKey: 'id',
		})
	}
	return Article
}
